<template>
  <div class="app-container home">
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="24" :lg="24" :xl="24">
        <el-alert
          v-for="item in alertList"
          :key="item"
          :title="item.title"
          style="margin-bottom: 10px;"
          type="warning"
          center
          show-icon>
        </el-alert>
      </el-col>
    </el-row>
    <el-row :gutter="20">
      <el-col :xs="24" :sm="24" :md="{span: 12, offset: 12}" :lg="{span: 12, offset: 12}" :xl="{span: 12, offset: 12}">
        <el-card class="update-log" shadow="never">
          <div slot="header" class="clearfix">
            <span><strong class="fontSize15">通知公告</strong></span>
          </div>
          <div class="body">
            <el-table v-loading="loading" :data="noticeList" size="mini">
              <el-table-column label="公告类型" align="center" prop="noticeType" width="100">
                <template slot-scope="scope">
                  <dict-tag :options="dict.type.sys_notice_type" :value="scope.row.noticeType"/>
                </template>
              </el-table-column>
              <el-table-column label="发布时间" align="center" prop="createTime" width="100">
                <template slot-scope="scope">
                  <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
                </template>
              </el-table-column>
              <el-table-column label="公告标题" align="left" header-align="center" prop="noticeTitle">
                <template slot-scope="scope">
                  <el-button type="text" @click="clickNoticeTitle(scope.row)">{{ scope.row.noticeTitle }}</el-button>
                </template>
              </el-table-column>
            </el-table>
            <pagination
              small
              layout="prev, pager, next"
              v-show="total>0"
              :total="total"
              :page.sync="queryParams.pageNum"
              :limit.sync="queryParams.pageSize"
              @pagination="getList"
            />
            <el-dialog :show-close="false" :visible.sync="open" custom-class="details_class customWidth" append-to-body :close-on-click-modal="false">
              <template #title>
                <dict-tag :options="dict.type.sys_notice_type" :value="form.noticeType"/>
              </template>
              <div>
                <el-form ref="form" :model="form" label-width="80px">
                  <el-row>
                    <el-col :span="24" align="center">
                      <span><h2>{{ form.noticeTitle }}</h2></span>
                      <el-divider />
                    </el-col>
                    <el-col :span="24" class="ql-editor">
                      <span>
                        <el-form-item v-html="form.noticeContent" :min-height="192"/>
                      </span>
                    </el-col>
                  </el-row>
                </el-form>
              </div>
              <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="open = false">关 闭</el-button>
              </div>
            </el-dialog>
          </div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import { homeListNotice, getAlertList } from "@/api/system/notice";

export default {
  name: "Index",
  dicts: ['sys_notice_type'],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 总条数
      total: 0,
      // 公告表格数据
      noticeList: [],
      // 弹出层标题
      title: "",
      alertList : [],
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 5,
        noticeTitle: undefined,
        createBy: undefined,
        status: undefined
      },
      // 表单参数
      form: {},
      client: "",
      isAdmin: "",
    };
  },
  created() {
    this.getList();
    this.getAlert();
  },
  methods: {
    /** 查询公告列表 */
    getList() {
      this.loading = true;
      homeListNotice(this.queryParams).then(response => {
        this.noticeList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 提示信息 */
    getAlert() {
      this.loading = true;
      getAlertList({}).then(response => {
        this.alertList = response.data;

      });
    },
    /** 点击公告标题操作 */
    clickNoticeTitle(row) {
      this.form = row;
      this.open = true;
      for (let i = 0; i <= this.dict.type.sys_notice_type.length; i++) {
        if (this.dict.type.sys_notice_type[i].value === row.noticeType) {
          this.title=this.dict.type.sys_notice_type[i].label;
          break;
        }
      }
    }
  }
};
</script>

<style scoped lang="scss">
.home {
  ::v-deep .ql-snow .ql-editor blockquote {
    border-left: 4px solid #ccc;
    margin-bottom: 5px;
    margin-top: 5px;
    padding-left: 16px;
  }
  ::v-deep .ql-snow .ql-editor pre.ql-syntax {
    background-color: #23241f;
    color: #f8f8f2;
    overflow: visible;
  }
  ::v-deep .el-card__body {
    padding: 5px;

  }
  ::v-deep .el-button--medium {
    font-size: 12px;
  }
  ::v-deep .fontSize15 {
    font-size: 15px;
  }
  ::v-deep .textAlignLeft {
    text-align: left;
  }
}

::v-deep .details_class .el-dialog__body {
  padding: 10px 20px;
  color: #606266;
  font-size: 14px;
  word-break: break-all;
}

::v-deep .ql-editor blockquote {
  border-left: 4px solid #ccc;
  margin-bottom: 5px;
  margin-top: 5px;
  padding-left: 16px;
}

::v-deep .ql-syntax {
  background-color: #23241f;
  color: #f8f8f2;
  overflow: visible;
}

::v-deep .customWidth {
  width: 45% !important;
  min-width: 300px !important;
}
</style>

